﻿var XmlHttp;
function getXmlHttp()
{
    try
    {
            //Neu la trinh duyet Firefox, Opera 8.0 +, Safari  
            XmlHttp = new XMLHttpRequest();			
    }
    catch (e1)
    {
        // Neu la Internet Explorer 6.0+
        try
        {
                XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e2)
        {
            try
            {
                //Neu la Internet Explorer 5.0+
                XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e3)
            {
                    alert("Trinh duyet cua ban khong ho tro Ajax (Your browser does not support Ajax)");
                    return false;
            }
        }
    }
}
function HandleResponse()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{		
                    ClearAndSetState(XmlHttp.responseText);
                  
		}
		else
		{
		    
			alert("Yeu cau cau ban khong thuc hien duoc" );                      
		}
	}	
}
function ClearAndSetState(text)
{
    document.getElementById("list").innerHTML = text;	
}
function Loading()
{
    document.getElementById("loading").style.display = 'block';
}
function Clear()
{
    document.getElementById("loading").style.display = 'none';
}

  /*----------------------------    */    
  function Search()
{    
    var rq = Math.random();
    var Name = document.getElementById("keyword1"); 
   
    if(Name.value != "")
    {                
        var requestUrl = 'Ajax.aspx?menu=search&prodName=' +encodeURIComponent(Name.value) + "&rq" + rq;                              
        getXmlHttp();	
        if(XmlHttp)
        {	
            XmlHttp.onreadystatechange = HandleResponse;		
            XmlHttp.open("GET", requestUrl,  true);		
            XmlHttp.send(null);		
        }
    }
}

function PageIndex(menu,subCate,p)
{   
    var requestUrl;
    requestUrl = "Ajax.aspx?menu="+menu+ "&p="+ p+"&idsubcat="+subCate;
	getXmlHttp();	
	if(XmlHttp)
	{	 
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}
  
function GetMenu(menu)
{              
 
        var rq = Math.random();   
        var requestUrl;
            requestUrl = "Ajax.aspx?menu=" + encodeURIComponent(menu)+"&rq=" + rq;
	getXmlHttp();	
	if(XmlHttp)
	{	  
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}
function GetListProductBySubCat(idCatSub) 
{            
        var requestUrl;
            requestUrl = "Ajax.aspx?menu=sp&idsubcat="+idCatSub;
	getXmlHttp();	
	if(XmlHttp)
	{	 
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}
function GetListProductByCat(idCat) 
{            
 var rq = Math.random();
        var requestUrl;
            requestUrl = "Ajax.aspx?menu=sp&idcat="+idCat+"&rq=" + rq;
	getXmlHttp();	
	if(XmlHttp)
	{	 
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}
function GetListCat(tabid,cat,page) 
{              
        var requestUrl;
            requestUrl = "Ajax.aspx?tabid=" + encodeURIComponent(tabid)+"&cat="+encodeURIComponent(cat)+"&page="+encodeURIComponent(page);
	getXmlHttp();	
	if(XmlHttp)
	{	  Loading();
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}

function GetProduct(tabid, cat,tab)
{              
    var rq = Math.random();   
    var requestUrl;
        requestUrl = "Ajax.aspx?tabid=" + encodeURIComponent(tabid)+"&cat="+encodeURIComponent(cat)+"&tab="+tab+"&rq=" + rq;
	getXmlHttp();	
	if(XmlHttp)
	{	 
        Loading();
        XmlHttp.onreadystatechange = HandleResponse;
		XmlHttp.open("GET", requestUrl,true);
		XmlHttp.send(null);                
	}      
}
function SearchAdvance(type)
{    
    var rq = Math.random();
    var keyWord22 = document.getElementById("keyWord22"); 
    var category =document.getElementById('category').value;   
    var manufacturer= document.getElementById('manufacturer').value;    
    var frommoney = document.getElementById("frommoney").value;    
    var tommoney = document.getElementById("tommoney").value;    
    if(type==2)
    {
        var requestUrl = 'Ajax.aspx?cat=16&keyWord22=' + keyWord22.value + '&category='+encodeURIComponent(category)+'&manufacturer='+encodeURIComponent(manufacturer)+'&frommoney='+encodeURIComponent(frommoney)+'&tommoney='+encodeURIComponent(tommoney)+"&rq" + rq;                              
        getXmlHttp();	
        if(XmlHttp)
        {	
            Loading();	
            XmlHttp.onreadystatechange = HandleResponse;		
            XmlHttp.open("GET", requestUrl,  true);		
            XmlHttp.send(null);		
        }
    }
}
function clearAll_Click()
{
	var numItems = document.forms[0].numItems.value;
	var check;
	for (var i = 1; i <= numItems; i++)
	{
		check = document.forms[0].item("check" + i);
		if (check.checked)
			check.click();
	}
}
function TestLogin(idProduct)
{       
    var frm = document;
    var Email=""; var pass="" ;var cbRemove=""; var txtQty="" ;
    var rq = Math.random();   
    var requestUrl;
        Email = frm.getElementById("txtUserName").value;
        Pass = frm.getElementById("txtPass").value;
        requestUrl = "Ajax.aspx?cat=9&UserName="+Email+"&Pass="+Pass+"&rq=" + rq;
    getXmlHttp();	
    if(XmlHttp)
    {	 
        Loading();  					
        XmlHttp.onreadystatechange = HandleResponse;
	    XmlHttp.open("GET", requestUrl,true);
	    XmlHttp.send(null);                
    }      
}
 function OpenWindow(theUrl,winName,features)
{
    window.open(theUrl+"&totalprice=ian3r9n03hltfa",winName,"width = 600px, height =650px, help=no, scroll=yes, status=no");                                 
} 
 function OpenWindowUploadFile(theUrl,winName,features)
{
    window.open(theUrl,winName,"width = 850px, height =650px, help=no, scroll=yes, status=no");                                 
}
function UploadHinh(txtImage, img, path)
{
    window.opener.document.getElementById(txtImage).value=path;
    window.opener.document.getElementById(img).src=path;
    window.close();window.history.go(1);
}
function resetDev()
{
    document.getElementById('inPutDevToCart').style.display="none";
    document.getElementById('DevSubmit').style.display="none";
}
